import { execute } from "../../database/connector";

import { ResearchGroupMembersQueries } from "../queries/research-group-members.query";
import { IResearchGroupMembers } from "../../models/research-group-members.model";

/**
 * gets active researchGroupMemberList
 */
export const getResearchGroupMembersList = async () => {
  return execute<IResearchGroupMembers[]>(ResearchGroupMembersQueries.GetResearchGroupMembers, []);
};

/**
 * gets a researchGroupMembers based on id provided
 */
export const getResearchGroupMembersById = async (id: IResearchGroupMembers['id']) => {
  return execute<IResearchGroupMembers>(ResearchGroupMembersQueries.GetResearchGroupMembersById, [id]);
};

/**
 * gets a researchGroupMembers based on group id provided
 */
export const getResearchGroupMembersByGroupId = async (researchGroupId: IResearchGroupMembers['id']) => {
  return execute<IResearchGroupMembers>(ResearchGroupMembersQueries.GetResearchGroupMembersByGroupId, [researchGroupId]);
};

/**
 * adds a new active researchGroupMembers record
 */
export const insertResearchGroupMembers = async (researchGroupMembers: IResearchGroupMembers[]) => {
  const result = await execute<{ affectedRows: number }>(ResearchGroupMembersQueries.AddResearchGroupMembers, [
    Object.values(researchGroupMembers)
  ]);
  return result.affectedRows > 0;
};


/**
 * updates researchGroupMembers information based on the id provided
 */
 export const deleteResearchGroupMembers = async (researchGroupId: IResearchGroupMembers['researchGroupId']) => {
  const result = await execute<{ affectedRows: number }>(ResearchGroupMembersQueries.DeleteResearchGroupMembersByGroupId, [
    researchGroupId
  ]);
  return result.affectedRows > 0;
};